package com.example.content.activity

import android.os.Bundle
import com.example.content.R
import com.example.content.databinding.ActivityChatBinding
import com.example.content.fragment.im.ChatFragment
import com.example.content.viewmodule.im.ChatViewModel
import com.example.content.viewmodule.im.MessageViewModel
import com.hyphenate.easeui.constants.EaseConstant
import com.hyphenate.easeui.ui.EaseChatFragment

class ChatActivity : BaseActivity<ActivityChatBinding, ChatViewModel>() {
    private lateinit var fragment: ChatFragment
    private var msgViewModel: MessageViewModel? = null
    private var toChatUsername: String? = null
    private var chatType = 0
    private var forwardMsgId: String? = null
    private var historyMsgId: String? = null

    override fun initView() {
        initSystemFit()
        fragment = ChatFragment()
        val bundle = Bundle()
        bundle.putString(EaseConstant.EXTRA_USER_ID, toChatUsername)
        bundle.putInt(EaseConstant.EXTRA_CHAT_TYPE, chatType)
        bundle.putString(EaseConstant.FORWARD_MSG_ID, forwardMsgId)
        bundle.putString(EaseConstant.HISTORY_MSG_ID, historyMsgId)
//        bundle.putBoolean("isRoaming", DemoHelper.getInstance().getModel().isMsgRoaming())
        fragment.arguments = bundle
        supportFragmentManager.beginTransaction()
            .replace(R.id.fl_fragment, fragment, ChatFragment::class.java.simpleName)
            .commitAllowingStateLoss()

        dataBinding.titleBarMessage.setRightImageResource(R.drawable.ic_more)
    }

    override fun initData() {
        toChatUsername = intent.getStringExtra(EaseConstant.EXTRA_USER_ID)
        chatType = intent.getIntExtra(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE)
        forwardMsgId = intent.getStringExtra(EaseConstant.FORWARD_MSG_ID)
        historyMsgId = intent.getStringExtra(EaseConstant.HISTORY_MSG_ID)
    }

    override fun initListener() {
        // TODO: 3/14/21 设置title
        dataBinding.titleBarMessage.setTitle("晴天的雨伞")
        dataBinding.titleBarMessage.setOnBackPressListener {
            finish()
        }
        dataBinding.titleBarMessage.setOnRightClickListener {

        }
    }

    override fun getLayoutId() = R.layout.activity_chat
}